import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  getConnection,
  Double,
  ColumnType,
  OneToMany,
  JoinTable,
  ManyToOne,
  Unique,
  PrimaryColumn,
} from 'typeorm';
import { Exclude } from 'class-transformer';
import moment = require('moment');
import { Orders } from './order.entity';

export enum MsgType {
  Word = 'word',
  Picture = 'picture',
  Goods = 'goods',
}

@Entity()
export class Message {
  @PrimaryColumn({
    type: 'char',
    comment: 'uuid',
    length: 36,
  })
  id: string;

  @Column({
    nullable: false,
    comment: 'content',
    length: 3000,
  })
  content: string;

  @Column({
    type: 'enum',
    enum: MsgType,
    nullable: false,
    comment: 'word:文字 picture:图片, goods:文字',
    default: MsgType.Word,
  })
  tp: MsgType;

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: 'createAt',
    update: false,
    transformer: {
      to: (value) => {
        return value;
      },
      from: (value) => {
        return moment(value).format('YYYY-MM-DD HH:mm:ss');
      },
    },
  })
  creatTime: Date;
}
